<template>
  <a-table
    rowKey="id"
    size="middle"
    bordered
    :loading="loading"
    :columns="columns"
    :dataSource="dataSource"
    :pagination="false"
  >
    <template slot="htmlSlot" slot-scope="text">
      <div v-html="text"></div>
    </template>

    <template slot="imgSlot" slot-scope="text,record">
      <div style="font-size: 12px;font-style: italic;">
        <span v-if="!text">无图片</span>
        <img
          v-else
          :src="getImgView(text)"
          :preview="record.id"
          alt
          style="max-width:80px;height:25px;"
        />
      </div>
    </template>

    <template slot="fileSlot" slot-scope="text">
      <span v-if="!text" style="font-size: 12px;font-style: italic;">无文件</span>
      <a-button
        v-else
        ghost
        type="primary"
        icon="download"
        size="small"
        @click="downloadFile(text)"
      >
        <span>下载</span>
      </a-button>
    </template>
  </a-table>
</template>

<script>
import { getAction } from '@api/manage'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'

export default {
  name: 'PurchaseOrderItemSubTable',
  mixins: [JeecgListMixin],
  props: {
    record: {
      type: Object,
      default: null
    }
  },
  data() {
    return {
      description: '申请的物品内嵌列表',
      disableMixinCreated: true,
      loading: false,
      dataSource: [],
      columns: [
        {
          title: '供应商编码',
          align: 'center',
          dataIndex: 'providerCode'
        },
        {
          title: '供应商',
          align: 'center',
          dataIndex: 'providerName'
        },
        {
          title: '产品编码',
          align: 'center',
          dataIndex: 'goodsCode'
        },
        {
          title: '产品分类',
          align: 'center',
          dataIndex: 'goodsTypeCode_dictText'
        },
        {
          title: '产品名称',
          align: 'center',
          dataIndex: 'goodsName'
        },
        {
          title: '单位',
          align: 'center',
          dataIndex: 'unit_dictText'
        },
        {
          title: '品牌',
          align: 'center',
          dataIndex: 'goodsBrand'
        },
        {
          title: '规格/尺寸/型号',
          align: 'center',
          dataIndex: 'size'
        },
        {
          title: '单价',
          align: 'center',
          dataIndex: 'unitPrice'
        },
        {
          title: '数量',
          align: 'center',
          dataIndex: 'number'
        },
        {
          title: '小计',
          align: 'center',
          dataIndex: 'total',
        },
        // {
        //   title: '附件',
        //   align: 'center',
        //   dataIndex: 'attachment',
        //   scopedSlots: { customRender: 'fileSlot' }
        // },
        {
          title: '创建人',
          align: 'center',
          dataIndex: 'createBy'
        },
        {
          title: '创建时间',
          align: 'center',
          dataIndex: 'createTime'
        },
        {
          title: '最后修改人',
          align: 'center',
          dataIndex: 'updateBy'
        },
        {
          title: '最后修改时间',
          align: 'center',
          dataIndex: 'updateTime'
        }
      ],
      url: {
        listByMainId: '/purchase/purchaseOrder/queryPurchaseOrderItemByMainId'
      }
    }
  },
  watch: {
    record: {
      immediate: true,
      handler() {
        if (this.record != null) {
          this.loadData(this.record)
        }
      }
    }
  },
  methods: {
    loadData(record) {
      this.loading = true
      this.dataSource = []
      getAction(this.url.listByMainId, {
        id: record.id
      })
        .then(res => {
          if (res.success) {
            this.dataSource = res.result.records
          }
        })
        .finally(() => {
          this.loading = false
        })
    },
purchase_order_item_onlChange(){
    return {
        number(){
            let id = event.row.id
            let number = event.row.number
            let unit_price = event.row.unit_price
            let target = event.target
            let nval = unit_price*number
            let otherValues  = {'total':nval}
                that.triggleChangeValues(otherValues,id,target)
        }
    }
}
  }
}
</script>

<style scoped>
</style>
